﻿using Framework.Core;
using Framework.Remoting.Client;
using Framework.Tests.Wcf.Client.ServiceDefinition;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Wcf.Client
{
    extern alias castlecore;

    public class ServiceClientFactoryTest
    {
        private readonly IServiceClientFactory target;
        private readonly MockRepository mockRepository;

        public ServiceClientFactoryTest()
        {
            mockRepository = new MockRepository();
            interceptorMock = mockRepository.StrictMock<castlecore.Castle.DynamicProxy.IInterceptor>();
            wcfInterceptorFactoryMock = mockRepository.StrictMock<IWcfInterceptorFactory>();
            target = new ServiceClientFactory(wcfInterceptorFactoryMock);
        }

        private readonly IWcfInterceptorFactory wcfInterceptorFactoryMock;

        private readonly castlecore.Castle.DynamicProxy.IInterceptor interceptorMock;

        [Fact]
        public void Ensure_ctor_compatibility()
        {
            Assert.NotNull(new ServiceClientFactory());
        }

        [Fact]
        public void When_Call_Get_Then_expected_Toto()
        {
            wcfInterceptorFactoryMock.Expect(x => x.Create<IContract>(EnvMode.Prod)).Return(interceptorMock);

            mockRepository.ReplayAll();
            Assert.NotNull(target.CreateProxy<IContract>(EnvMode.Prod));

            mockRepository.VerifyAll();
        }

        [Fact]
        public void Do_not_create_ProxyGenerator_for_each_use()
        {
            Assert.True(ServiceClientFactory.ProxyGenerator == ServiceClientFactory.ProxyGenerator);
        }
    }
}